﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ComicBook.Data.IDataAdapters.Interfaces;
using ComicBook.Data.IDataAdapters.Adapters;
using ComicBook.DataModels;
using ComicBook.web.Models;

namespace ComicBook.web.Controllers
{
    public class ComicController : Controller
    {
        IComicBookAdapter _adapter;
        public ComicController()
        {
            _adapter = new ComicBookAdapter();
        }
        public ComicController(IComicBookAdapter adapter)
        {
            _adapter = adapter;
        }

        public ActionResult ComicDetail(int id)
        {
            ComicAuthorVM vm = new ComicAuthorVM();
            vm.Comic = _adapter.GetComic(id);
            vm.Author = _adapter.GetAuthorForComic(id);
            return View(vm);
        }
        [HttpGet]
        public ActionResult EditComic(int id)
        {
            Comic comic = _adapter.GetComic(id);
            return View(comic);
        }
        [HttpPost]
        public ActionResult EditComic(Comic comic)
        {
            comic = _adapter.UpdateComic(comic);
            return RedirectToAction("ComicDetail/" + comic.Id);
        }
        public ActionResult DeleteComic(int id)
        {
            _adapter.DeleteComic(id);
            return Redirect("/Home/Index");
        }
	}
}